<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<meta name="apple-mobile-web-app-status-bar-style" content="black" />
	<meta name="format-detection" content="telephone=no"/>
	<title>新华保险培训微平台</title>
	<link rel="stylesheet" href="../css/lt_common.css">
	<link rel="stylesheet" href="../css/ranking_list.css">
	<link rel="stylesheet" href="../css/iscroll.css">
	<script src="../js/jquery.js"></script>
	<script src="../js/jquery.form.js"></script>
	<script src="../js/common.js"></script>
	<script src="../js/iscroll.js"></script>
	<script src="../js/teacherclub/ranking_list.js"></script>
</head>
<body>
	<div class="page">
		
		<div id="wrapper">
			<div id="scroller">
				
				<div id="pullDown">
					<span class="pullDownIcon"></span><span class="pullDownLabel">下拉刷新...</span>
				</div>
				<div id="itemsLists">
					<div class="list_content">
					<p><i class="queen"></i>讲师人气排行榜</p>
					<div class="flex_box"></div>
					</div>
				</div>
				<div>
				</div>
				<div id="pullUp">
					<span class="pullUpIcon"></span><span class="pullUpLabel">查看更多>></span>
				</div>
			</div>
		</div>
		<!-- 添加发布按钮 -->
		<div class="main_button">
			<input type="button">
		</div>
	</div>
	<div class="mask_div">
		<!-- 选择发布类型 -->
		<div class="choose_content">
			<div class="btn_content">
				<label for="" class="menu_show1"><input type="button" class="img_btn">动态</label>
				<label for="" class="menu_show2"><input type="button" class="video_btn">课程</label>
			</div>
			<div class="off_button">
				<input type="button">
			</div>
		</div>	
		<!-- 发布动态	 -->
		<div class="text_img">
		<form id="publishImg" method="post" enctype="multipart/form-data">
			<input type="hidden" name="type" value="photo">
			<textarea id="content" maxlength=100 minlength=6  name="content" placeholder="说点儿什么吧..."></textarea>
			<!-- <input type="file" name="filedata"  value="" contenteditable="false"> -->
			<div style="margin :0px auto; width:990px;">
				<input type="file" name="filedata" id="doc" multiple="multiple" style="display:none;" onchange="javascript:setImagePreviews();" accept="image/*">
				<div id="dd" style="width:296px;"></div>
			</div>
			<img src="../img/icon-addimg.png" id="fileElemt" alt="">
			<span class="add_font">添加图片</span>
			<div class="textbtn_content clear">
				<input id="cancle" type="button" value="取消">
				<input id="push" type="button" value="发送">
			</div>
		</form>		
		</div>
	</div>
	<!-- 放大图片 -->
	<div class="imgorgin"></div>
	<!-- 搜索侧边栏 -->
	<div class="side_content">
		<div class="side_left"></div>
		<div class="sider_right" id="sider_right">
			<div class="search_content">
				<span class="search_icon"></span>
				<input type="search" placeholder="搜索">
			</div>
			<div class="check_content">
				<p>话题筛选</p>
				<form action="check_box" id="check_items">
					<label for="all">
						<i class="all_icon"></i><input id="all" type="checkbox" value="" name="">全部<i class=""></i>
					</label>
					<label for="lesson">
						<i class="lesson_icon"></i><input id="lesson" type="checkbox" value="" name="vido">课程<i class=""></i>
					</label>
					<label for="pdf">
						<i class="pdf_icon"></i><input id="pdf" type="checkbox" value="" name="pdf">课件<i class=""></i>
					</label>
					<label for="eg">
						<i class="eg_icon"></i><input id="eg" type="checkbox" value="" name="example">案例<i class=""></i>
					</label>
				</form>
			</div>
			<div class="person_page">
				<img src="../img/icon-per_page.png" alt="">
				个人主页
				<i class="into_icon"></i>
			</div>
		</div>
		
	</div>
</body>
</html>
<!--控制蒙层显示隐藏-->
<script>
	$(function(){

		//detialFun('agentclub/main?openid='+openid+'&type='+);
		if(user_status == '1'){
			var str_button = '';
			var str_button_width = '';
			$.ajax({
				url: API_URL+"agent/getbyopenid?openid="+openid,
				type: 'get',
				dataType: "JSON",
				data:'',
				async: false,
				success: function (obj){
					if (obj.status.code == 0) {
						if(obj.data[0].agent_category==3){
							//显示4个 +2个
							//<!-- 显示案例时js设置296行label宽度为25% -->
							str_button = '<label for="" class="menu_show3"><input type="button" class="pdf_btn">课件</label>'+
								'<label for="" class="menu_show4"><input type="button" class="eg_btn">案例</label>';
							str_button_width = '25%';

						}else{
							if(obj.data[0].agent_category==1){
								if((obj.data[0].agent_level).indexOf('二级')!=-1){
									//显示4个
									str_button = '<label for="" class="menu_show3"><input type="button" class="pdf_btn">课件</label>'+
								'<label for="" class="menu_show4"><input type="button" class="eg_btn">案例</label>';
								str_button_width = '25%';
								}else{
									//不显示最后一个
									str_button = '<label for="" class="menu_show3"><input type="button" class="pdf_btn">课件</label>';
									str_button_width = '33.3%';
								}
							}
						}
						//alert(str_button);
						$('.btn_content label:last-child').after(str_button);
						if(str_button_width!=''){
							$('.mask_div .btn_content label').css('width',str_button_width);
						}
						$('.main_button input').show();
					}else{
						alert('服务错误');
					}
				},
				error: function (data){
					console.log("服务器异常!");
				}
			});
			
			
			
		}
		//首次加载列表
		detialFun('agentclub/main?openid='+openid);
		//$('#itemsLists .list_content').html(Str);
		Str = '<div class="showitemdiv">'+ Str + '</div>';
		$('#itemsLists .list_content').after(Str);

		//获取排行榜
		rankFun();

		showclick();

		imgOrgin();
		$('.main_button input').on('click',function(){
			$('.mask_div').fadeIn();
			$('.choose_content').show();
			$('.main_button').hide();
		});
		$('.off_button input').on('click',function(){
			$('.mask_div').hide();
			$('.main_button').show();
		});
		$('.btn_content .img_btn').on('click',function(){
			$('.choose_content').hide();
			$('.text_img').show();
		});
		$('#cancle').on('click',function(){
			$('.mask_div').hide();
			$('.text_img').hide();
			$('.main_button').show();
		});
		//联动上传图片
		$('#fileElemt').on('click',function(){
			if ($('#dd').html() == '') {
				$('#doc').click();
			}else{
				alert('只能上传一张图片哦！');
			}
			
		});	
		//更多
		$('.more_detials').on('click',function(){
			$('.side_content').fadeIn('fast',function(){
				$('.sider_right').addClass('show');
			});
		})
		$('.side_left').on('click',function(){
			$('.side_content').fadeOut('fast', function() {
				$('.sider_right').removeClass('show');
			});
		});
		
		//注册筛选点击事件
		checkLabel();

		//搜索框聚焦
		$('.search_content input').focus(function() {
			window.location = 'search_items.html';
		});
	});
</script>
<!--多图片上传预览功能-->
<script type="text/javascript">
    //多图片上传预览功能
    function setImagePreviews(avalue) {
        var docObj = document.getElementById("doc");
        var dd = document.getElementById("dd");
        dd.innerHTML = "";
        var fileList = docObj.files;
        for (var i = 0; i < fileList.length; i++) {            

            dd.innerHTML += "<div style='float:left;width: 24%;' > <img id='img" + i + "'  /> </div>";
            var imgObjPreview = document.getElementById("img"+i); 
            if (docObj.files && docObj.files[i]) {
                //火狐下，直接设img属性
                imgObjPreview.style.display = 'block';
                imgObjPreview.style.width = '61px';
                imgObjPreview.style.height = '61px';
                //imgObjPreview.src = docObj.files[0].getAsDataURL();
                //火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式
                imgObjPreview.src = window.URL.createObjectURL(docObj.files[i]);
            }
            else {
                //IE下，使用滤镜
                docObj.select();
                var imgSrc = document.selection.createRange().text;
                alert(imgSrc)
                var localImagId = document.getElementById("img" + i);
                //必须设置初始大小
                localImagId.style.width = "61px";
                localImagId.style.height = "61px";
                //图片异常的捕捉，防止用户修改后缀来伪造图片
                try {
                    localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
                    localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
                }
                catch (e) {
                    alert("您上传的图片格式不正确，请重新选择!");
                    return false;
                }
                imgObjPreview.style.display = 'none';
                document.selection.empty();
            }
        }  
        return true;
    }
</script>
<!--加载更多&&下拉刷新-->
<script type="text/javascript">
	//上拉刷新
	var myScroll,
		pullDownEl, pullDownOffset,
		pullUpEl, pullUpOffset,
		generatedCount = 0;

	function pullDownAction () {
		setTimeout(function () {	// <-- Simulate network congestion, remove setTimeout from production!
			 detialFun('agentclub/main?operation=down&createtime_time='+downTime+'&openid='+openid+'&type='+typeValue);
			 $('#itemsLists .showitemdiv .items_detials:first-child').before(Str);
			myScroll.refresh();
			showclick();
			imgOrgin();	// Remember to refresh when contents are loaded (ie: on ajax completion)
		}, 1000);	// <-- Simulate network congestion, remove setTimeout from production!
	}

	function pullUpAction () {
		setTimeout(function () {	// <-- Simulate network congestion, remove setTimeout from production!
			detialFun('agentclub/main?operation=up&createtime_time='+upTime+'&openid='+openid+'&type='+typeValue);
			if(Str == ''){
				$('#pullUp').hide();
			}else{
				$('#pullUp').show();
				$('#itemsLists .showitemdiv .items_detials:last-child').after(Str);
			}
			myScroll.refresh();
			showclick();
			imgOrgin();	// Remember to refresh when contents are loaded (ie: on ajax completion)
		}, 1000);	// <-- Simulate network congestion, remove setTimeout from production!
	}

	function loaded() {
		pullDownEl = document.getElementById('pullDown');
		pullDownOffset = pullDownEl.offsetHeight;
		pullUpEl = document.getElementById('pullUp');	
		pullUpOffset = pullUpEl.offsetHeight;
		
		myScroll = new iScroll('wrapper', {
			useTransition: true,
			topOffset: pullDownOffset,
			onRefresh: function () {
				if (pullDownEl.className.match('loading')) {
					pullDownEl.className = '';
					pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...';
				} else if (pullUpEl.className.match('loading')) {
					pullUpEl.className = '';
					pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
				}
			},
			onScrollMove: function () {
				if (this.y > 5 && !pullDownEl.className.match('flip')) {
					pullDownEl.className = 'flip';
					pullDownEl.querySelector('.pullDownLabel').innerHTML = '释放刷新...';
					this.minScrollY = 0;
				} else if (this.y < 5 && pullDownEl.className.match('flip')) {
					pullDownEl.className = '';
					pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...';
					this.minScrollY = -pullDownOffset;
				} else if (this.y < (this.maxScrollY - 5) && !pullUpEl.className.match('flip')) {
					pullUpEl.className = 'flip';
					pullUpEl.querySelector('.pullUpLabel').innerHTML = '释放刷新...';
					this.maxScrollY = this.maxScrollY;
				} else if (this.y > (this.maxScrollY + 5) && pullUpEl.className.match('flip')) {
					pullUpEl.className = '';
					pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
					this.maxScrollY = pullUpOffset;
				}
			},
			onScrollEnd: function () {
				if (pullDownEl.className.match('flip')) {
					pullDownEl.className = 'loading';
					pullDownEl.querySelector('.pullDownLabel').innerHTML = '加载中...';				
					pullDownAction();	// Execute custom function (ajax call?)
				} else if (pullUpEl.className.match('flip')) {
					pullUpEl.className = 'loading';
					pullUpEl.querySelector('.pullUpLabel').innerHTML = '加载中...';				
					pullUpAction();	// Execute custom function (ajax call?)
				}
			}
		});
		
		setTimeout(function () { document.getElementById('wrapper').style.left = '0'; }, 800);
	}

	document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);

	document.addEventListener('DOMContentLoaded', function () { setTimeout(loaded, 200); }, false);
</script>
